﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;

namespace Microsoft.Popfly.GameCreator.GameEngine
{
    public partial class SilverlightConsoleItem : UserControl
    {
        private string m_message;
        public string Message
        {
            get
            {
                return m_message;
            }
            set
            {
                m_message = value;
                UpdateTextBox();
            }
        }

        private ConsoleFormat m_format;
        public ConsoleFormat Format
        {
            get
            {
                return m_format;
            }
            set
            {
                m_format = value;
                UpdateTextBox();
            }
        }

        public void UpdateTextBox()
        {
            if (Message != null)
            {
                switch (Format)
                {
                    case ConsoleFormat.None:
                        MessageBox.Foreground = new SolidColorBrush(Colors.Black);
                        MessageBox.Text = Message;
                        break;
                    case ConsoleFormat.Warning:
                        MessageBox.Foreground = new SolidColorBrush(Colors.Brown);
                        MessageBox.Text = "WARNING:  " + Message;
                        break;
                    case ConsoleFormat.Error:
                        MessageBox.Foreground = new SolidColorBrush(Colors.Red);
                        MessageBox.Text = "ERROR:  " + Message;
                        break;
                    case ConsoleFormat.Heading:
                        MessageBox.Foreground = new SolidColorBrush(Colors.Black);
                        MessageBox.Text = Message;
                        MessageBox.FontWeight = FontWeights.Bold;
                        break;
                    default:
                        throw new NotImplementedException(
                            "ConsoleFormat of + '" + Format.ToString() + "' not supported by SilverlightConsoleItem."
                            );
                }
            }
        }
        

        public double TextBoxWidth
        {
            get
            {
                return MessageBox.Width;
            }
            set
            {
                MessageBox.Width = value;
            }
        }

        public string GetText()
        {
            return MessageBox.Text;
        }

        public SilverlightConsoleItem(string message, ConsoleFormat format, double width)
        {
            InitializeComponent();
            m_message = message;
            m_format = format;
            TextBoxWidth = width;
            UpdateTextBox();
        }
    }
}
